#include <iostream>
#include "../spline_functions.h"

int main() {
    // 测试线性B样条函数
    std::cout << "-------Problem 1: Testing linearspline by the linear function 'y = 2x'-------" << std::endl;
    std::vector<double> knots_B = {0, 1, 2, 3, 4};
    std::vector<double> coefficients_B = {0, 2, 4, 6, 8}; // y = 2x;
    LinearSpline_B linearSpline_B(1, knots_B, coefficients_B); // 线性B样条的阶数为1

    // 测试点
    std::vector<double> test_points_B = {0.5, 1.5, 2.5, 3.5};
    std::cout << "---Part1. Testing LinearSpline_B:" << std::endl;
    for (double x : test_points_B) {
        try {
            double value = linearSpline_B.evaluate(x);
            std::cout << "spline value at x = " << x << " is " << value << std::endl;
        } catch (const std::exception& e) {
            std::cerr << "Error evaluating LinearSpline_B at x = " << x << ": " << e.what() << std::endl;
        }
    }

    // 测试pp形式的线性样条函数
    std::vector<double> knots_p = {0, 1, 2, 3, 4};
    std::vector<double> coefficients_p = {0, 2, 4, 6, 8};
    LinearSpline_p linearSpline_p(knots_p, coefficients_p);

    // 测试点
    std::vector<double> test_points_p = {0.5, 1.5, 2.5, 3.5};
    std::cout << "---Part2. Testing LinearSpline_p:" << std::endl;
    for (double x : test_points_p) {
        try {
            double value = linearSpline_p.evaluate(x);
            std::cout << "spline value at x = " << x << " is " << value << std::endl;
        } catch (const std::exception& e) {
            std::cerr << "Error evaluating LinearSpline_p at x = " << x << ": " << e.what() << std::endl;
        }
    }

    return 0;
}